/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86155
 * date: 2024-01-31
 * Time: 10:39
 *
 * @author 方法使用
 */

public class Test {
    //斐波那契数
    public static int feibo(int n){
        if(n == 1 || n==2){
            return 1;
        }
        return febo(n-1)+febo(n-2);
    }
    public static void main(String[] args) {
        System.out.println(febo(6));
    }
    //求一个多位数各个位上相加的和
    public static int bitadd(int n){
        if(n>9){
            return n%10+bitadd(n/10);
        }else {
            return n;
        }
    }
    public static void main10(String[] args) {
        System.out.println(bitadd(1729));
    }
    //递归求1到10
    public static int sum(int n){
        if(n==1){
            return 1;
        }
        return n+sum(n-1);
    }
    public static void main9(String[] args) {
        System.out.println(sum(10));
    }
    //按照顺序输出1234（ 1 2 3 4）
    public static void pin(int n){
        if(n>9){
            pin(n/10);
        }
        System.out.print(n%10+" ");
    }
    public static int uploap(int n){
        if(n < 10){
            return n;
        }

        return  n%10+uploap(n/10);
    }
    public static void main8(String[] args) {
        System.out.println(uploap(123));
        System.out.println();
        pin(123);
    }
    //利用递归求阶乘
    public static int jiemul(int n){
        if(n == 1){
            return 1;
        }
        return n * jiemul(n - 1);
    }
    public static void main7(String[] args) {
        System.out.println(jiemul(5));
    }
    //斐波那契数列
    public static int febo(int n){
        int a = 1;
        int b = 1;
        int c = 1;
        for (int i = 3; i <= n; i++) {
            c = a+b;
            a = b;
            b = c;
        }
        return c;
    }
    public static void main6(String[] args) {
        System.out.println(febo(1));
        System.out.println(febo(2));
        System.out.println(febo(3));
        System.out.println(febo(4));
        System.out.println(febo(5));
    }
    //求两个数的最大值
    public static int max(int a,int b){
        return a>b ? a:b;
    }
    public static int max(int a,int b,int c){
        int max1 = max(a,b);
        return max1>c ?max1:c;
    }
    public static void main5(String[] args) {
        int a = 10;
        int b = 20;
        int c = 30;
        System.out.println(max(a,b,c));
    }
    //方法实现阶乘相加
    public static int mulsum(int n){
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            int ret = 1;
            for (int j = 1; j <= i; j++) {
                ret *= j;
            }
            sum += ret;
        }
        return sum;
    }
    public static void main4(String[] args) {
        int n = 4;
        int end = mulsum(n);
        System.out.println(end);
    }
    //重载
    public static int Add(int a,int b){
        return a+b;
    }
    public static double Add(double a,double b){
        return a+b;
    }
    public static double Add(int a,int b,double c){
        return a+b+c;
    }
    public static double Add(int a,double b,int c){
        return a+b+c;
    }
    //实现数字相加
    //小数相加
    public static void main3(String[] args) {
        double a = 10.0;
        double b = 20.0;
        double c = Add(a,b);
        System.out.println(c);
    }
    //整数相加
    public static void main2(String[] args) {
        int a = 10;
        double b = 20;
        int c = 30;
        double d = Add(a,c,b);
        System.out.println(d);
    }
    //判断闰年
    public static void leapyear(int a) {
        if ((a % 4 == 0) && (a % 100 != 0)) {
            System.out.println("闰年");
        } else if (a % 400 == 0) {
            System.out.println("leap year");
        } else {
            System.out.println("no leap year");
        }
    }
    public static void main1(String[] args) {
        int a = 1605;
        leapyear(a);
    }
}

